package com.skillworld.webapp.model.tutorial;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import com.skillworld.webapp.model.user.User;

@Entity
@Table(name="MarkedTutorial")
public class MarkedTutorial 
{
	
	public enum Mark { RATED, DONE, FAVORITE, TODO }
	
	private Long markedId;
	private User user;
	private Tutorial tutorial;
	private Mark mark;
	private Integer rating;
	
	
	protected MarkedTutorial() 
	{

	}

	public MarkedTutorial(User user, Tutorial tutorial, Mark mark)
	{
        this.user = user;
        this.tutorial = tutorial;
        this.mark = mark;
        this.rating = null;
    }

    public MarkedTutorial(User user, Tutorial tutorial, Mark mark, 
                            int rating) 
	{
	    this.user = user;
		this.tutorial = tutorial;
		this.mark = mark;
		this.rating = rating;
	}


	@SequenceGenerator(name="MarkedTutorialIdGenerator",sequenceName="MarkedTutorialSeq")
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO,generator="MarkedTutorialIdGenerator")
	@Column(name="idMarked")
	public Long getMarkedId() {
		return markedId;
	}
	
	protected void setMarkedId(Long markedId) {
		this.markedId = markedId;
	}
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="idUser")
	public User getUser() {
		return user;
	}
	
	public void setUser(User user) {
		this.user = user;
	}

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="idTutorial")
	public Tutorial getTutorial() {
		return tutorial;
	}
	
	protected void setTutorial(Tutorial tutorial) {
		this.tutorial = tutorial;
	}
	
	@Enumerated(EnumType.STRING)
	@Column(name="mark")
	public Mark getMark() {
		return mark;
	}
	
	public void setMark(Mark mark) {
		this.mark = mark;
	}
	
	@Column(name="rating")
	public Integer getRating() {
		return rating;
	}
	
	public void setRating(Integer rating) {
		this.rating = rating;
	}

}
